package com.appbee.media.client.ui;

import javax.inject.Inject;

import com.appbee.core.client.design.PageStyle;
import com.appbee.media.client.design.ThumbnailCellListResources;
import com.appbee.media.client.design.ThumbnailCellListStyle;
import com.appbee.media.client.presenter.MediaActivity;
import com.appbee.media.shared.MediaProxy;
import com.google.gwt.core.client.GWT;
import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.event.dom.client.ClickHandler;
import com.google.gwt.uibinder.client.UiBinder;
import com.google.gwt.uibinder.client.UiField;
import com.google.gwt.user.client.ui.Button;
import com.google.gwt.user.client.ui.Composite;
import com.google.gwt.user.client.ui.FlowPanel;
import com.google.gwt.user.client.ui.Image;
import com.google.gwt.user.client.ui.Widget;

public class MediaView extends Composite implements MediaActivity.View
{

	private static MediaViewUiBinder uiBinder = GWT
			.create(MediaViewUiBinder.class);

	interface MediaViewUiBinder extends UiBinder<Widget, MediaView>
	{
	}
	@UiField(provided=true)
	PageStyle style;
	
	@UiField
	FlowPanel buttonPanel;
	
	Button uploadButton;
	
	Button prevButton;
	
	Button nextButton;
	
	
	@UiField
	Image image;
	
	private MediaActivity activity;

	private final ThumbnailCellListStyle cellListStyle;
	
	@Inject
	public MediaView(PageStyle style, ThumbnailCellListResources listRes)
	{
		this.style = style;
		cellListStyle = listRes.cellListStyle();
		cellListStyle.ensureInjected();
		
		initWidget(uiBinder.createAndBindUi(this));
		image.setStyleName(cellListStyle.fullView());
		
		prevButton = new Button("Fyrri");
		prevButton.addClickHandler(new ClickHandler()
		{
			
			@Override
			public void onClick(ClickEvent event)
			{
				activity.doPrevius();
			}
		});
		nextButton = new Button("Næsta");
		nextButton.addClickHandler(new ClickHandler()
		{
			
			@Override
			public void onClick(ClickEvent event)
			{
				activity.doNext();
			}
		});
	}

	
	@Override
	public void setActivity(MediaActivity activity)
	{
		this.activity = activity;
	}

	@Override
	public void showMedia(MediaProxy media)
	{
		image.setUrl("/serve?blob-key="+media.getStrId());
	}

	



}
